#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

typedef long long ll;
typedef double db;
typedef vector < int > vec;
typedef pair < int , int > pii;

int read() {
    int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-',ch = getchar();
    while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

const int N = 2e5 + 10;
const int L = N * 60;
const int T = (1 << 20) - 1;

int ndn, ch[L][2], rt, ans[L], n, q, a[N];
int hav[L][2], xtag[L];

void reval(int x, int val, int d) {
	if(!x) return;
	if(val >> d & 1) swap(ch[x][0], ch[x][1]);
	int ls = hav[x][0], rs = hav[x][1];
	hav[x][0] = (ls & (val ^ T)) | (rs & val); hav[x][1] = (ls & val) | (rs & (val ^ T));
	xtag[x] ^= val;
}

void pu(int x) {
	ans[x] = ans[ch[x][0]] + ans[ch[x][1]];
	hav[x][0] = hav[ch[x][0]][0] | hav[ch[x][1]][0];
	hav[x][1] = hav[ch[x][0]][1] | hav[ch[x][1]][1];
}

void pd(int x, int d) {
	if(xtag[x]) {
		reval(ch[x][0], xtag[x], d - 1); reval(ch[x][1], xtag[x], d - 1);
		xtag[x] = 0; 
	}
}

void split(int &x, int &y, int xl, int xr, int l = 0, int r = T, int d = 19) {
	if(!x) return; if(xl <= l && r <= xr) return y = x, x = 0, void();
	int mid = l + r >> 1; pd(x, d); y = ++ndn;
	if(xl <= mid) split(ch[x][0], ch[y][0], xl, xr, l, mid, d - 1);
	if(xr > mid) split(ch[x][1], ch[y][1], xl, xr, mid + 1, r, d - 1);
	pu(x), pu(y);
}

int merge(int x, int y, int d = 19) {
	if(d == -1 || !x || !y) return x | y;
	ch[x][0] = merge(ch[x][0], ch[y][0]); ch[x][1] = merge(ch[x][1], ch[y][1]);
	pu(x);
	return x;
}

void orit(int x, int val, int d = 19) {
	if(!(val & hav[x][0] & hav[x][1])) return reval(x, val & hav[x][0], d);
	pd(x, d);
	if(val >> d & 1) {
		reval(ch[x][0], 1 << d, d - 1);
		ch[x][1] = merge(ch[x][1], ch[x][0], d - 1); ch[x][0] = 0; pu(x);
		return;
	}
	orit(ch[x][0], val, d - 1); orit(ch[x][1], val, d - 1);
	pu(x);
}

void insert(int &x, int val, int d = 19) {
	if(!x) x = ++ndn; if(d == 0) { ans[x] = 1; hav[x][0] = T ^ val; hav[x][1] = val; return; }
	if(val >> d & 1) insert(ch[x][1], val, d - 1); else insert(ch[x][0], val, d - 1);
	pu(x);
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
#endif
    n = in, q = in; rep(i, 1, n) a[i] = in, insert(rt, a[i]);
	int A; 
	while(q--) {
		int op = in, l = in, r = in, x;
		split(rt, A, l, r);
		if(op == 1) x = in, reval(A, T, 19), orit(A, T ^ x), reval(A, T, 19);
	    else if(op == 2) x = in, reval(A, x, 19);
		else if(op == 3) x = in, orit(A, x);
		else printf("%d\n", ans[rt]);
		rt = merge(rt, A);
	}
}
